<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return=array();
	$info=$this->plugin_setting('basic');
	//从请求参数中获取code
	$code=$_RQ['code'];
	if(!$code){
		$message['error']=2;
	}else{
		$shouci=pdo_get('jy_goodsfw_log',array('uniacid'=>$_SESSION['uniacid'],'code'=>$code,'merchid'=>$_SESSION['onemerchid']),'','createtime asc');
		$last=pdo_get('jy_goodsfw_log',array('uniacid'=>$_SESSION['uniacid'],'code'=>$code,'merchid'=>$_SESSION['onemerchid']),'','createtime desc');
		$shouci['createtime']=$shouci['createtime']?:time();
		$info['shouci']=date('Y-m-d H:i:s',$shouci['createtime']);
		$info['userip']=$last['userip'];
		//code被查询次数
		$count=pdo_count('jy_goodsfw_log',array('uniacid'=>$_SESSION['uniacid'],'code'=>$code,'merchid'=>$_SESSION['onemerchid']));
		$isfirst=$count==0?1:0;
		$secury=$this->plugin_setting('secury');
		$logid=$this->check_code($code);
		$goods_id=pdo_getcolumn('jy_goodsfw_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$logid),'goods_id');
        $goods=pdo_get('jy_goodsfw_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goods_id));
		if($goods['merchid']){
			$info=$this->plugin_setting('basic'.$goods['merchid']);
		}
		$message['error'] = $logid?0:1;
		if($message['error'] == 0){
			$message['msg']='该产品属于正品！请放心使用！';
			$num=$secury['num'];
			if($num && $num<=$count){
				$message['error']=1;
				$message['msg']='O~该产品属于正品！但超过查询次数！';
			}
            $count++;
			$goods['cangdi']=json_decode($goods['cangdi'],true);
			$goods['diytext']=json_decode($goods['diytext'],true);
			$goods['params']=json_decode($goods['params'],true);
			$goods['images']=json_decode($goods['images'],true);
			if($goods['isweishop'] && $goods['goodsid']){
				$goodsnew=pdo_get('jy_weishop_goods',array('id'=>$goods['goodsid'],'uniacid'=>$_SESSION['uniacid']));
				$goodsnew['pici']=$goods['pici'];
				$goodsnew['cangday']=$goods['cangday'];
				$goodsnew['cangdi']=$goods['cangdi'];
				$goodsnew['diytext']=$goods['diytext'];
				$goodsnew['image']=$goodsnew['image']?tomedia($goodsnew['image']):'';
				$goodsnew['video']=$goodsnew['video']?tomedia($goodsnew['video']):'';
				$goodsnew['images']=json_decode($goodsnew['images'],true);
				$goodsnew['params']=$goods['params'];
				foreach($goodsnew['images'] as &$image){
					$image=tomedia($image);
				}
				array_unshift($goodsnew['images'],tomedia($goodsnew['image']));
				$goodsnew['content']=$goods['content']?:$goodsnew['content'];
				$goodsnew['url']='jy_weishop/goods.detail//id='.$goods['goodsid'];
				$goods=$goodsnew;
			}
			paixu($goods['params'],'paixu','asc');
		}else{
			$message['msg']='O~！该产品非正品！';
		}
	}
	$info['code']=$code;
    $info['count']=$count;
	$return['url']=custom_url('jy_goodsfw/search/main/',true);
	$return['hdps']=$info['hdps'][0];
	$return['info']=$info;
	$return['goods']=$goods;
	$return['message']=$message;
	set_html('title','在线防伪溯源查询');
	exi($return);
}	
?>